package com.frog.service.friend.service.message;


import com.frog.common.util.ConstantUtil;
import com.frog.service.friend.mapper.FriendAddMessageDOMapper;
import com.frog.service.friend.model.domain.FriendAddMessageDO;
import com.frog.service.friend.utils.FriendRelationshipUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class FriendAddMessageServiceImpl implements FriendAddMessageService {

    @Autowired
    private FriendAddMessageDOMapper friendAddMessageDOMapper;


    @Override
    public boolean deleteAddMessage(Integer userId, Integer friendUserId) {

        Long id = FriendRelationshipUtil.processRelationId(userId, friendUserId);
        if (id == null || id == 0) return false;
        try {
            FriendAddMessageDO fm = friendAddMessageDOMapper.selectFriendAddMessageById(id);
            if (fm != null && fm.getToUserId().equals(userId) && ConstantUtil.common.STATUS_0.equals(fm.getDeleteStatus())) {
                FriendAddMessageDO friendAddMessageDOUpdate = new FriendAddMessageDO();
                friendAddMessageDOUpdate.setId(id);
                fm.setUpdateTime(System.currentTimeMillis());
                fm.setDeleteStatus(ConstantUtil.common.STATUS_1);
                friendAddMessageDOMapper.updateFriendAddMessageById(fm);
                return true;
            }
        } catch (Exception ex) {
            log.error("deleteAddMessage user:{},friend:{} Exception ", userId, friendUserId, ex);
        }
        return false;
    }
}